package com.kkw.shoppingmall.product.web;

import com.alibaba.fastjson.JSON;
import com.kkw.shoppingmall.product.service.SkuInfoService;
import com.kkw.shoppingmall.product.vo.SkuItemVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author Kevin
 * @date 2021-06-08
 **/
@Slf4j
@Controller
public class ItemController {

    @Autowired
    private SkuInfoService skuInfoService;


    /**
     * 展示当前商品的详情
     * @param skuId
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String skuItem(@PathVariable("skuId") Long skuId, Model model) throws Exception {
        System.out.println("准备查询"+skuId);
        SkuItemVo skuItemVo=  skuInfoService.item(skuId);
        log.info("商品列表->{}",JSON.toJSONString(skuItemVo));
        model.addAttribute("item",skuItemVo);
        return "item";
    }
}
